﻿#region licence
//  Copyright 2008 Michael Cromwell

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino.DSL;
using Boo.Lang.Compiler;
using Boo.Lang.Compiler.Steps;
using System.Reflection;
using log4net.altconf.Steps;
using log4net.altconf;
using log4net.altconf.Macros;

namespace log4net.altconf
{
    /// <summary>
    /// Used by Rhino DSL to enable custom steps when building
    /// DSL instance
    /// </summary>
    public class Log4NetDslEngine : DslEngine
    {
        protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
        {
            compiler.Parameters.References.Add(typeof(log4net.ILog).Assembly);
            
            pipeline.Insert(1, new ImplicitBaseClassCompilerStep(
                                    DslBaseType,
                                    "Process",
                                    "log4net.altconf.Macros", "log4net",
                                    "log4net.Appender", "log4net.Layout", 
                                    "log4net.Layout.Pattern", "Boo.Lang"));

            pipeline.Insert(2, new UseSymbolsStep());
            pipeline.Insert(3, new WithAppendersTransformerCompilerStep());
            pipeline.InsertBefore(
                        typeof(ProcessMethodBodiesWithDuckTyping),
                        new UnderscorNamingConventionsToPascalCaseCompilerStep());

        }
        
        protected virtual Type DslBaseType
        {
            get { return typeof(Log4NetDslConfiguration); }
        }
        
    }
}
